﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using tactics.Interfaces;
using tactics.Commands;

namespace tactics
{
    public class CommandQueue
    {
        static CommandQueue instance;
        Queue<ICommand> commandList;

        ICommand command;

        public static CommandQueue Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new CommandQueue();
                }
                return instance;
            }
        }
        
        public CommandQueue()
        {
            instance = this;
            commandList = new Queue<ICommand>();
            command = null;
        }

        public void AddCommand(ICommand command)
        {
            commandList.Enqueue(command);
        }

        public void InvokeNext()
        {
            if (command != null)
            {
                if (command.Finished)
                    command = null;
            }
            else if (commandList.Count > 0 && command == null)
            {
                command = commandList.Dequeue();
                command.Execute();
            }
        }
    }
}